package com.fgs.common.widget;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.fgs.common.CommonDialog;
import com.fgs.common.R;
import com.fgs.common.interf.OnDialogClickListener;


/**
 * @author fgs
 * @date 2020/4/9
 * @description
 **/
public class PermissionDialog extends CommonDialog {
    private TextView contentTextView;
    private TextView refusedTextView;
    private TextView agreeTextView;
    private final OnDialogClickListener onDialogClickListener;
    private String content;

    public PermissionDialog(@NonNull Context context, OnDialogClickListener onDialogClickListener) {
        super(context, R.style.style_select_dialog);
        this.onDialogClickListener = onDialogClickListener;
    }

    public PermissionDialog setContent(String content) {
        this.content = content;
        return this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_permission);
        setCancelable(false);
        setCanceledOnTouchOutside(false);
        contentTextView = findViewById(R.id.dialog_permission_contentTextView);
        refusedTextView = findViewById(R.id.dialog_permission_refusedTextView);
        agreeTextView = findViewById(R.id.dialog_permission_agreeTextView);

        contentTextView.setText(content);

        agreeTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (onDialogClickListener != null)
                    onDialogClickListener.onPositiveClick();
            }
        });

        refusedTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (onDialogClickListener != null)
                    onDialogClickListener.onNegativeClick(false);
            }
        });
    }


}
